<?php
    $this->layout('base.phtml', [
        'title' => _('Account deletion'),
        'canonical' => url_full('account deletion'),
        'back_options' => [
            'track' => false,
        ],
        'has_errors' => $error || $errors,
    ]);
?>

<div class="section section--small section--longbottom">
    <div class="section__title">
        <h1><?= _('Account deletion') ?></h1>
    </div>

    <div class="section__intro">
        <p>
            <strong><?= _f('You’re connected as %s.', protect($current_user->username)) ?></strong>
        </p>

        <p>
            <?= _('You’re about to delete your account and your data will be lost. This can’t be canceled!') ?>
        </p>
    </div>

    <form method="post" action="<?= url('delete account') ?>">
        <?= $this->include('alerts/_error.phtml', ['message' => $error]) ?>

        <input type="hidden" name="csrf" value="<?= csrf_token() ?>" />

        <div class="form-group <?= isset($errors['password_hash']) ? 'form-group--invalid' : '' ?>">
            <label for="password">
                <?= _('Your password') ?>
            </label>

            <div class="form-group__stack" data-controller="input-password">
                <input
                    id="password"
                    name="password"
                    type="password"
                    autofocus
                    required
                    data-input-password-target="input"
                    aria-describedby="password-desc"
                />

                <button
                    type="button"
                    class="no-mobile js-only"
                    data-action="input-password#toggle"
                    data-input-password-target="button"
                    aria-label="<?= _('Show password as plain text. Note: this will visually expose your password.') ?>"
                >
                    <?= icon('eye') ?>
                    <?= _('Show') ?>
                </button>
            </div>

            <div id="password-desc">
                <?php if (isset($errors['password_hash'])): ?>
                    <p class="form-group__error">
                        <span class="sr-only"><?= _('Error') ?></span>
                        <?= $errors['password_hash'] ?>
                    </p>
                <?php endif; ?>

                <p class="form-group__caption">
                    <?= _('You must type your password so we can confirm your identity.') ?>
                </p>
            </div>
        </div>

        <div class="form__actions">
            <button type="submit" class="button--danger">
                <?= _('Delete your account') ?>
            </button>
        </div>
    </form>
</div>
